﻿#include "financenetworkaccessmanager.h"

const QString FINANCE_BASE_URL = BASE_URL+"finance/";
const QString FINANCE_ADD_FINANCE_ITEM = FINANCE_BASE_URL+"addFinanceItem";
const QString FINANCE_GET_FINANCE_ITEMS = FINANCE_BASE_URL+"getFinanceItems";
const QString FINANCE_ADD_FINANCE_RECORD = FINANCE_BASE_URL+"addFinanceRecord";
const QString FINANCE_DEL_FINANCE_ITEM = FINANCE_BASE_URL+"deleteFinanceItem";
const QString FINANCE_UPDATE_FINANCE_ITEM = FINANCE_BASE_URL+"updateFinanceItem";
const QString FINANCE_FINANCE_QUERY = FINANCE_BASE_URL+"financeQuery";
FinanceNetworkAccessManager::FinanceNetworkAccessManager(QObject *parent) : BaseNetworkAccessManager(parent)
{

}

void FinanceNetworkAccessManager::addFinanceItem(QString companyId, int type, QString category, QString subject){
    QByteArray data;
    data.append("companyId="+companyId+"&");
    data.append("type="+QString("%1").arg(type)+"&");
    data.append("category="+category+"&");
    data.append("subject="+subject);

    doPost(FINANCE_ADD_FINANCE_ITEM, data);
}

void FinanceNetworkAccessManager::getFinanceItems(QString companyId){
    QByteArray data;
    data.append("companyId="+companyId);

    doPost(FINANCE_GET_FINANCE_ITEMS, data);
}

void FinanceNetworkAccessManager::addFinanceRecord(
        QString username,
        QString companyId,
        QString itemId,
        double money,
        QString remark){
    QByteArray data;

    data.append("username="+username+"&");
    data.append("companyId="+companyId+"&");
    data.append("itemId="+itemId+"&");
    data.append("money="+QString("%1").arg(money)+"&");
    data.append("remark="+remark);

    doPost(FINANCE_ADD_FINANCE_RECORD, data);
}

void FinanceNetworkAccessManager::deleteFinanceItem(QString companyId, QString itemId){
    QByteArray data;
    data.append("companyId="+companyId+"&");
    data.append("itemId="+itemId);

    doPost(FINANCE_DEL_FINANCE_ITEM, data);
}

void FinanceNetworkAccessManager::updateFinanceItem(
        QString companyId,
        QString itemId,
        int type,
        QString category,
        QString subject){
    QByteArray data;
    data.append("companyId="+companyId+"&");
    data.append("itemId="+itemId+"&");
    data.append("type="+QString("%1").arg(type)+"&");
    data.append("category="+category+"&");
    data.append("subject="+subject);

    doPost(FINANCE_UPDATE_FINANCE_ITEM, data);
}

void FinanceNetworkAccessManager::financeQuery(
        QString username,
        int type1,
        int type2,
        QString startDate,
        QString endDate){
    QByteArray data;

    data.append("username="+username+"&");
    data.append("type1="+QString("%1").arg(type1)+"&");
    data.append("type2="+QString("%1").arg(type2)+"&");
    data.append("startDate="+startDate+"&");
    data.append("endDate="+endDate);

    doPost(FINANCE_FINANCE_QUERY, data);
}
